package org.su.generalmvc.scanner;

import com.thoughtworks.xstream.XStream;
import org.su.generalmvc.config.XSSHConfig;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.io.FileInputStream;
import java.io.FileNotFoundException;

/**
 * xml配置加载器，负责加载xssh.xml配置文件
 * 
 * @author yangchuan
 * 
 */
public class XMLConfigLoader {

	public static final String DEFAULT_XML_CONFIG = "WEB-INF/xssh.xml";

	protected static final Log logger = LogFactory
			.getLog(XMLConfigLoader.class);

	/**
	 * 加载配置环境
	 * @param path
	 * @return 返回一个xml对应的java配置对象
	 * @throws java.io.FileNotFoundException
	 */
	public XSSHConfig loadXmlConfig(String path) throws FileNotFoundException {
		
		XStream xStream = new XStream();
		xStream.alias("config", XSSHConfig.class);
		xStream.autodetectAnnotations(true);
		return  (XSSHConfig) xStream
				.fromXML(new FileInputStream(path));
	}


}
